package com.yc.RSS.reader;

import com.yc.RSS.CommonInformationItem;
import com.yc.RSS.RSSDataCapturer;
import com.yc.RSS.buffer.NewsBuffer;
import com.yc.RSS.writer.NewsWriterTask;
import org.apache.log4j.Logger;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.util.List;

/**
 * 下载新闻源RSS
 * @author zwei
 * @create 2024-07-24 16:59
 */
public class NewProductTask implements Runnable{
    private Logger logger=Logger.getLogger(NewsWriterTask.class);
    private String url;
    private String name;
    private NewsBuffer newsBuffer;

    public NewProductTask(String url, String name, NewsBuffer newsBuffer) {
        this.url = url;
        this.name = name;
        this.newsBuffer = newsBuffer;
    }

    @Override
    public void run() {
        RSSDataCapturer capturer=new RSSDataCapturer(name);
        List<CommonInformationItem>list= null;
        try {
            list = capturer.load(url);
        } catch (Exception e){
            e.printStackTrace();
            logger.error(name+"的新闻源下载失败");
        }
        //存到缓存队列中
        for (  CommonInformationItem item:list   ){
            newsBuffer.add(item);
        }
        logger.info("下载："+name+"源的"+url+"完成");
    }
}
